package com.haha.viewholder;

import org.kymjs.kjframe.KJBitmap;
import org.kymjs.kjframe.bitmap.BitmapConfig;

import com.haha.mylife.R;
import com.haha.tools.AutoUpdate;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnCheckedChanged;
import butterknife.OnClick;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.view.View;
import android.widget.CheckBox;

public class LeftMenuViewHoler {
	@Bind(R.id.cbShowWelcome1) CheckBox cbShowWelcome1;
	@Bind(R.id.cbAuto) CheckBox cbAuto;
	SharedPreferences sp;
	
	Context ctx;
	
	public LeftMenuViewHoler(View v){
		ButterKnife.bind(this,v);
		ctx=v.getContext();
		sp=v.getContext()
			.getSharedPreferences("app.cfg", Context.MODE_PRIVATE);
		cbShowWelcome1.setChecked(
				sp.getBoolean("isFirst", false));
		cbAuto.setChecked(
				sp.getBoolean("auto", false));
	}
	@OnCheckedChanged(R.id.cbShowWelcome1) 
	void cbShowWelcome1Change(){
		sp.edit()
		.putBoolean("isFirst", cbShowWelcome1.isChecked())
		.commit();;
		
	}
	@OnCheckedChanged(R.id.cbAuto) 
	void cbAutoChange(){
		sp.edit()
		.putBoolean("auto", cbAuto.isChecked())
		.commit();		
	}
	@OnClick(R.id.btnClearCache) void clearCacheClick(){
		 new KJBitmap().cleanCache();
	}
	
	@OnClick(R.id.btnUpdate) void updateClick(){
		AutoUpdate au=new AutoUpdate((Activity) ctx);
		au.checkUpdate();
	}
}
